package model.repositorio.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class ConexaoBD {

	private static EntityManager entityManager;
	private static EntityManagerFactory factory;
	
	public static EntityManager getEntityManager() {
        
		if (factory == null){
			factory = Persistence.createEntityManagerFactory("tarefas");
		}
		if (entityManager == null) {
            entityManager = factory.createEntityManager();
        }
 
        return entityManager;
    }
	
	public static void close(){
		
		if(entityManager != null){
			entityManager.close();
			entityManager = null;
		} 
		
		if (factory != null) {
			factory.close();
			factory = null;	
		}
		
	}
	
}
